home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / bagtag2.zip / GOTO.CB < prev    next >
Text File  |  1993-03-21  |  3KB  |  120 lines

  1. /****************************************************************************
  2. *
  3. *   goto.cb                                             21Mar93
  4. *
  5. *   Pre-processor for goto_line, so that
  6. *       Esc kills the command
  7. *       entering a numeric string acts just like goto_line
  8. *       entering a non-numeric string "foo" acts like tag foo
  9. *       entering "+", "-" steps to next, previous function header
  10. *       Enter acts like ctag
  11. *
  12. *   Contains macros:
  13. *       goto
  14. *
  15. *   Copyright (c) 1992 B. Goldstein -- Pequod Software
  16. *
  17. *   Change History (see also individual entries):
  18. *   Date    Who What
  19. *   ------- --- -------------
  20. *   17Nov92 BAG First draft
  21. *   19Nov92 BAG Trim leading and trailing blanks from arg
  22. *   21Nov92 BAG Add "-" and "+" to go to prior, subsequent function header
  23. *   25Nov92 BAG Dropped cbrief.h for distribution
  24. *   29Nov92 BAG Trim arg before checking it
  25. *   21Mar93 BAG If shift key down, do goto column
  26. *
  27. ****************************************************************************/
  28. /*  Definitions     */
  29.  
  30. #include <cbrief.h>
  31.  
  32. /***************************************************************************/
  33. /*  Externals       */
  34.  
  35. void ctag (void);
  36. void tag (~string);
  37.  
  38. void center_line (void);
  39.  
  40. /***************************************************************************/
  41.  
  42. int goto (~string)
  43.  
  44.  {  string _goto_arg;
  45.     global _goto_arg;
  46.  
  47.     int retcode;
  48.  
  49.  
  50.     /*═════════════════════════════════*/
  51.     /*  First, see if "modified goto"  */
  52.     /*═════════════════════════════════*/
  53.  
  54.     if ((inq_kbd_flags () & (LEFT_SHIFT | RIGHT_SHIFT)))
  55.      {  int col;
  56.  
  57.         if (get_parm (0, col, "Go to column: ") <= 0 || col == 0)
  58.             return (0); 
  59.         move_abs (NULL, col);
  60.         return (1);
  61.      }
  62.  
  63.  
  64.     /*══════════════════════*/
  65.     /*  "Un-modified" goto  */
  66.     /*══════════════════════*/
  67.  
  68.     // Esc ==> get out
  69.     if (get_parm (0, _goto_arg, 
  70.                     "Go to line, function, or tag: ", NULL, _goto_arg) <= 0)
  71.         return (0); 
  72.  
  73.     _goto_arg = ltrim (trim (_goto_arg));
  74.  
  75.     // No arg ==> ctag
  76.     if (strlen (_goto_arg) == 0)
  77.      {  ctag ();    
  78.         return (1);
  79.      }
  80.  
  81.     // Numeric arg ==> old goto_line
  82.     if (index ("0123456789", substr (_goto_arg, 1, 1)) != 0)
  83.         return (goto_line (atoi (_goto_arg))); 
  84.  
  85.  
  86.     // search for a function definition
  87.     if (_goto_arg == "+" || _goto_arg == "-")
  88.      {  save_position ();
  89.  
  90.         if (_goto_arg == "+")
  91.          {  next_char ();
  92.             retcode = search_fwd ("<[A-Za-z_.][~;\n]@([~;]@>");
  93.          }
  94.         else 
  95.          {  prev_char ();
  96.             retcode = search_back ("<[A-Za-z_.][~;\n]@([~;]@>");
  97.          }
  98.  
  99.         if (retcode <= 0)
  100.          {  restore_position (1);
  101.             message ("No %s function.",
  102.                                      ((_goto_arg == "+") ? "next" : "prev"));
  103.             return (0);
  104.          }
  105.         else 
  106.          {  restore_position (0);
  107.             center_line ();
  108.             message ("Found %s function.", 
  109.                                     ((_goto_arg == "+") ? "next" : "prev"));
  110.             return (1);
  111.          }
  112.      }
  113.  
  114.     // Tag to explicit argument
  115.     tag (_goto_arg);
  116.     return (1);
  117.  }
  118.  
  119. /************************* end of goto.cb file *****************************/
  120.